package com.duanjw.java.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 数据库工具类
 *
 * @author duanjw
 */
public class DBUtil {
    private static Connection connection;
    public static String DRIVER = "com.mysql.cj.jdbc.Driver";
    public static String URL = "jdbc:mysql://rm-2zehn7gz3ai658mw3wo.mysql.rds.aliyuncs.com/test";
    public static String USER = "insight";
    public static String PASSWORD = "Insight123";

    static {
        try {
            // 1. 加载驱动程序
            Class.forName(DRIVER);
            // 2. 获得数据库连接
            connection = DriverManager.getConnection(URL, USER, PASSWORD);
            connection.createStatement();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取数据库链接
     *
     * @return
     */
    public static Connection getConnection() {
        return connection;
    }
}
